package mc.support.util;

import com.taobao.api.domain.Item;

import java.util.List;

/**
 * Created with IntelliJ IDEA. <br/>
 * Author: francis Yun    <br/>
 * Date: 2013-12-09  <br/>
 */
public final class TaobaoPojoUtil {

    private static final String IMG_SIZE_SUFFIX = "_80x80.jpg";
    private static final String DETAIL_URL_PREFIX = "http://item.taobao.com/item.htm?id=";

    private TaobaoPojoUtil() {}

    public static List<Item> resetDetailUrl(List<Item> items) {
        if ( null != items && items.size() > 0 ) {
            for ( Item i : items ) {
                Long numIid = i.getNumIid();
                if ( null != numIid ) {
                    i.setDetailUrl( PlainUtil.connectToStr( getDetailUrlPrefix(), numIid ) );
                }
            }
        }

        return items;
    }

    public static String getMiniImgUrl(String imgUrl) {
        if ( null != imgUrl && !imgUrl.endsWith( IMG_SIZE_SUFFIX ) ) {
            return PlainUtil.connectToStr( imgUrl, IMG_SIZE_SUFFIX );
        }
        return imgUrl;
    }

    public static String getDetailUrlPrefix() {
        return DETAIL_URL_PREFIX;
    }

}
